import axios from 'axios'
import { Message } from 'element-ui'
const request = axios.create({
  baseURL: '/biz/',
  // baseURL: process.env.VUE_APP_BASE_URL,
  withCredentials: true,
  timeout: 30000
})
request.interceptors.request.use(
  (config) => {
    // 处理POST请求 params传参
    if (config.method !== 'get' && config.data?.isParams) {
      delete config.data?.isParams
      config.params = config.data
      delete config.data
    }
    // document.cookie = 'logon_token=20250529113104-2505'
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)
request.interceptors.response.use(
  (response) => {
    if (response.data instanceof Blob) {
      return response.data
    }
    return response.data
  },
  (error) => {
    console.log(error)
    Message.error(error.response.data?.message || '未知错误')
  }
)
export default request
